#include <iostream>
#include <sstream>
#include <cmath>
using namespace std;

string player[101];
int output[101];

void all_replace(string &s, string old_val, string new_val)
{
    int pos = 0;
    while ((pos = s.find(old_val, pos)) != s.npos)
    {
        s.erase(pos, old_val.length());
        s.insert(pos, new_val);
        pos++;
    }
}

int to_num(string &s)
{
    all_replace(s, "y", "0");
    all_replace(s, "n", "1");
    int num = 0;
    for (int i = 0; i < s.length(); i++)
    {
        num += (s[i] - '0') * pow(2, s.length() - 1 - i);
    }
    return num;
}

int main()
{
    int length, n;
    cin >> length >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> player[i];
        output[i] = to_num(player[i]) + 1;
    }
    for (int i = 0; i < n; i++)
    {
        cout << output[i];
        if (i != n - 1)
        {
            cout << endl;
        }
    }
    return 0;
}